<template>
	<view style="background-color: #fff;">
		<u-navbar titleStyle="font-size:40rpx;color:#333" :placeholder='true' title="个人信息" :autoBack="true">
			<view  class="homeRed fontS32" slot="right"  @click="set">
				保存
			</view>		
		</u-navbar>
		<view class="headerBox  padding32">
			<view class="flexJBC">
				<view class="fontS32" style="width: 50%;">
					头像
				</view>
				<view class="flex" @click="unImage()">
					<view  style="width:120rpx ;height: 120rpx;">
						<u-image :showError='false' :showLoading='false' :src="avatar"  width="120rpx" height="120rpx"
							shape="circle" />
						</u-image>
					</view>
					<u-icon name="arrow-right" size="12" color="#999" style="margin-left: 26rpx;"></u-icon>
				</view>
			</view>
		</view>
		<view class="flexJBC name"> 
			<view class="fontS32" style="width: 50%;">
				用户名
			</view>
			<view class="co9">
				<input type="text" v-model="nickname" style="text-align: right;">
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo:'',
				nickname: '',
				avatar: ''
			}
		},
		methods: {
			// 提交用户信息
			set(){
				this.$my.post('/index/user/update_user',{nickname:this.nickname,avatar:this.avatar}).then(res=>{
					this.$my.toast(res.message)
					if(res.code==200){
						this.init()
					}
				})
			},
			// 头像上传
			async unImage() {
			   let respic=await this.$my.choosepic('/index/com/file')
			   this.avatar=respic.file_path//图片url
			},
			// 初始化
			init() {
				this.$my.get('/index/user/get_user_info').then(res=>{
					console.log(res.data);
					if(res.code==200){
						uni.setStorageSync('userInfo',res.data)
					   this.nickname=res.data.nickname
					   this.avatar=res.data.avatar
					}
				})
			}
		},
		onLoad() {
			this.init()
		}
	}
</script>

<style lang="less" scoped>
 /deep/ .u-image__loading{
 		position: inherit !important
 	}
	.name {
		padding: 24rpx 32rpx;
		box-sizing: border-box;
		border-top: 2rpx solid #F5F5F5;
	}
</style>
